import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 支付模块-订单表
 */
@Entity('pay_order')
export class PayOrderEntity extends BaseEntity {
  @Index()
  @Column({ comment: '用户ID' })
  userId: number;

  @Index({ unique: true })
  @Column({ comment: '订单号', length: 32 })
  orderNo: string;

  @Column({ comment: '订单标题', length: 200, nullable: true })
  title: string;

  @Column({ comment: '订单描述', type: 'text', nullable: true })
  description: string;

  @Column({
    comment: '订单类型',
    dict: ['充值余额', '购买流量', '电话通知充值', '物联网卡充值', '短信通知充值'],
    default: 0,
  })
  orderType: number;

  @Column({ comment: '订单金额', type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({
    comment: '订单状态',
    dict: ['待支付', '已支付', '已取消', '已退款'],
    default: 0,
  })
  status: number;

  @Column({
    comment: '支付方式',
    dict: ['微信支付', '支付宝', '余额支付', '银行卡'],
    default: 0,
  })
  paymentMethod: number;

  @Column({ comment: '支付时间', nullable: true })
  payTime: Date;

  @Column({ comment: '取消时间', nullable: true })
  cancelTime: Date;

  @Column({ comment: '退款时间', nullable: true })
  refundTime: Date;

  @Column({ comment: '业务ID', nullable: true })
  businessId: number;

  @Column({ comment: '业务类型', length: 50, nullable: true })
  businessType: string;

  @Column({ comment: '扩展信息', type: 'json', nullable: true })
  extInfo: any;

  @Column({ comment: '备注', type: 'text', nullable: true })
  remark: string;

  // 充值余额相关字段
  @Column({ comment: '充值金额', type: 'decimal', precision: 10, scale: 2, nullable: true })
  rechargeAmount: number;

  // 购买流量相关字段
  @Column({ comment: '流量包大小(MB)', nullable: true })
  trafficSize: number;

  @Column({ comment: '流量包有效期(天)', nullable: true })
  trafficValidDays: number;

  // 电话通知充值相关字段
  @Column({ comment: '充值分钟数', nullable: true })
  callMinutes: number;

  // 物联网卡充值相关字段
  @Column({ comment: '物联网卡ICCID', length: 20, nullable: true })
  iccid: string;

  @Column({ comment: '物联网卡充值流量(MB)', nullable: true })
  iotTrafficSize: number;

  // 短信通知充值相关字段
  @Column({ comment: '短信条数', nullable: true })
  smsCount: number;
}